package com.itheima.tanhua.admin.controller;

import com.itheima.model.domain.DashUsersDto;
import com.itheima.model.domain.Distribution;
import com.itheima.model.vo.DashUsersVo;
import com.itheima.model.vo.SummaryVo;
import com.itheima.tanhua.admin.service.DashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/dashboard")
public class DashboardController {
    @Autowired
    private DashboardService dashboardService;
    /**
     * 概要统计信息
     */
    @GetMapping("/summary")
    public ResponseEntity summary(){
        SummaryVo summaryVos = dashboardService.querySummary();
        return ResponseEntity.ok(summaryVos);
    }

    /**
     * 新增、活跃用户、次日留存率
     * */
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam Integer type,@RequestParam(defaultValue = "-1")Long sd,@RequestParam(defaultValue = "-1")Long ed){

        DashUsersVo vo =  dashboardService.queryUsersByType(type,sd,ed);
        return ResponseEntity.ok(vo);
    }
    /**
     * 注册用户分布，行业top、年龄、性别、地区
     * */
    @GetMapping("/distribution")
    public ResponseEntity distribution(@RequestParam(defaultValue = "-1")Long sd,@RequestParam(defaultValue = "-1")Long ed){

        Distribution distribution =  dashboardService.distribution(sd,ed);
        return ResponseEntity.ok(distribution);
    }
}
